package com.besttone.search;

import com.besttone.app.SuggestionProvider;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.provider.SearchRecentSuggestions;
import android.view.View;
import android.view.Window;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ImageButton;
import android.widget.ListView;
import android.widget.TextView;

public class MoreKeywordActivity extends Activity {
	private View view;
	private ImageButton btn_back;
	private ListView keywordListView;
	private String[] mKeywordArray = null;
	private SearchRecentSuggestions suggestions;
	
	@Override
	public void onCreate(Bundle bundle) {
		super.onCreate(bundle);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		view = this.getLayoutInflater().inflate(R.layout.more_keyword, null);
		setContentView(view);
		
		btn_back = (ImageButton) findViewById(R.id.left_title_button);
		btn_back.setOnClickListener(backListner);
		
		suggestions = new SearchRecentSuggestions(this,
				SuggestionProvider.AUTHORITY, SuggestionProvider.MODE);
		
		mKeywordArray = getResources().getStringArray(R.array.hot_search_items);
		
		keywordListView =(ListView) findViewById(R.id.keyword_list);
		
		
		ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this, R.layout.more_keyword_item, mKeywordArray);
		
		keywordListView.setFastScrollEnabled(true);
		keywordListView.setTextFilterEnabled(true);
		keywordListView.setAdapter(arrayAdapter);
		keywordListView.setOnItemClickListener(mOnClickListener);
		
	}
	
	private ImageButton.OnClickListener backListner = new ImageButton.OnClickListener() {
		public void onClick(View v) {
			finish();
		}
	};
	
	private AdapterView.OnItemClickListener mOnClickListener = new AdapterView.OnItemClickListener() {
		public void onItemClick(AdapterView<?> parent, View v, int position,
				long id) {
			TextView text = (TextView)v;
			String keyword = text.getText().toString();
			Intent intent = new Intent();
			intent.setClass(MoreKeywordActivity.this, SearchResultActivity.class);
			Bundle bundle = new Bundle();
    		bundle.putString("keyword", keyword);
    		intent.putExtras(bundle);
    		
    		suggestions.saveRecentQuery(keyword, null);
    		
    		startActivity(intent);
		}
	};
	
}